package com.hb.C_Lambda表达式和集合.闭包

fun main() {
    val x = makeFun()
    //每次调用函数的值都不一样，说明count的作用域没有被释放
    x()
    x()
    x()
    x()
    x()

    println("-----")
    //斐波那契
    val fibo = fibonacci()
    println(fibo())
    println(fibo())
    println(fibo())

}

//函数的返回值是一个函数
fun makeFun():()->Unit{
    var count=0
    return fun (){
        println(++count)
    }
}

//斐波那契函数
fun fibonacci():()->Long{
    var first=0L
    var second=1L
    return fun():Long{
        val result=second
        second+=first
        first=second-first
        return first
    }
}